 def execute_horizontal_split
        new_connection = create_new_connection
        FasterCSV.foreach("hr_split_config.csv") do |row|
              generate_header_file(row[0],new_connection)
              puts "Header file sucessfully generated..."
              FasterCSV.foreach("#{row[0]}_header.csv") do |header_row|
                    header_counter = 0
                    for field in header_row
                          if field != nil
                              col_specs = get_the_col_spec_for_single_col(field,row[0],new_connection) 
                              if header_counter == 0
                                    new_connection.query("CREATE TABLE #{row[1]} (#{field} #{col_specs})")
                                    header_counter = header_counter + 1
                              else
                                    new_connection.query("ALTER TABLE #{row[1]} ADD `#{field}` #{col_specs}")
                              end
                          end	
                    end	
                end
                puts "New table schema was succesfully created..."
                split_table_data(row[0],row[1],row[2],new_connection)
        end		
 end


 def split_table_data(source_table,destination_table,split_limit,new_connection)
        all_records = new_connection.query("SELECT * FROM #{source_table} LIMIT #{split_limit}")
        for record in all_records
            if record != nil
                record = record.join(',')
                puts "INSERT INTO #{destination_table} VALUES (#{record})"
            end	
        end
 end	 
 

 def generate_horizontal_split_config_file
        config_file = File.new("hr_split_config.csv","w") 
        config_file.write("original_table_name,new_table_name,split_position")
        config_file.close
 end	 
